<template>
  <div class="pay_count">
    <div class="right">
      合计<span>￥{{ totalPrice }}</span>
    </div>
    <div class="left" @click="pay">立即结算</div>
  </div>
</template>

<script>
 import {Debounce,Throttle} from "@/utils/tools";
export default {
  data(){
    return{
      from:""
    }
  },
  
  props: {
    totalPrice: {
      type: Number,
    },
    orderKey: {
      type: String,
    },
    id:{
        type:Number
    },
    useIntegral:{
      type:Number
    },
    payType:{
      type:String
    },
    mask:{
      type:String
    }
  },
  watch:{
    
    
  },
  methods: {
    // 点击支付
    pay() {
      let url = `/api/order/create/${this.orderKey}`;
      let token = localStorage.getItem("token");
      let data = {
        addressId: this.id,
        
        bargainId: 0,
        combinationId: 0,
        couponId: 0,
        from: "weixinh5",
        mark: this.mask,
        payType:this.payType,
        phone: "",
        pinkId: 0,
        real_name: "",
        seckill_id: 0,
        shipping_type: 1,
        store_id: 0,
        useIntegral: this.useIntegral,
      };
      let pro = axios({
        method: "post",
        url: url,
        data: data,
        headers: {
          "Authori-zation": "Bearer " + token,
        },
      })
        .then((res) => {
          console.log("支付成功", res.data);

          this.$paytoast.show("支付成功",1500)
          setTimeout(()=>{
            if(res.data.msg.includes('成功')){
              this.$router.push("/order/status/"+res.data.data.result.orderId+"/1")
            }else if(res.data.msg.includes('错误') || res.data.msg.includes('余额不足')){
              console.log("支付失败")
              
              this.$router.push("/order/status/"+res.data.data.result.orderId+"/0?msg="+res.data.msg)
            }

            
            
          },1500)
        })
        .catch((err) => {
          console.log("支付失败");
          this.$toast.show("支付失败",1500)
        });
    },
    clickPay:Debounce(function(){
      this.pay()
    },300)
  },
};
</script>

<style lang="scss" scoped>
.pay_count {
  position: fixed;
  bottom: 0;
  left: 0;
  height: 48px;
  width: 100%;
  background-color: #fff;
  z-index: 100;
  padding: 0 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .right {
    font-size: 14px;
    color: #333;
    span {
      color: #fc4141;
    }
  }
  .left {
    width: 135px;
    height: 35px;
    color: #fff;
    text-align: center;
    line-height: 35px;
    background-color: #fc4141;
    border-radius: 17.5px;
    font-size: 16px;
  }
}
</style>

